package org.dong.servlet;


import org.dong.Tool.CodePicture;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.RenderedImage;
import java.io.IOException;

@WebServlet("/code")
public class CodeServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Object[] image = CodePicture.createImage();
        String codetStr = (String) image[0];
        System.out.println(codetStr);
        HttpSession session = req.getSession();
        session.setAttribute("codeStr",codetStr);

        ImageIO.write((RenderedImage) image[1],"jpg",resp.getOutputStream());
    }
}
